package cn.ssm.controller;

import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import cn.ssm.biz.impl.UserroleBizimpl;
import cn.ssm.pojo.User;
import cn.ssm.pojo.Userrole;

@Controller
@RequestMapping("/userrole")
public class UserroleController {
	@Autowired
	@Qualifier("userroleBiz")
	private UserroleBizimpl userroleBizimpl;

	@RequestMapping("/addUserRole")
	public String addUsersRoel(Userrole ur,HttpSession session){
		User x=userroleBizimpl.selectUsersTopId();
		int uId=x.getId();
		ur.setUserId(uId);
		int roleId=Integer.parseInt(session.getAttribute("roleId").toString());
		ur.setRoleId(roleId);
		String url = "";
		int a = userroleBizimpl.AddUserRole(ur);
		if(a > 0){
			url = "navbar";
		}else{
			url="404";
		}
		return url;
	}

	@RequestMapping("/updateUserRole")
	public String updateUserRole(HttpSession session){
		String url = "";
		int upUId = Integer.parseInt(session.getAttribute("uidxx").toString());
		int upRoleId = Integer.parseInt(session.getAttribute("upRoleId").toString());
		int num = userroleBizimpl.UpdateRole(upUId, upRoleId);
		if(num > 0){
			url = "navbar";
		}else{
			url="404";
		}
		return url;
	}
	
	@RequestMapping("/findUserRoleByNo")
	public String findUserRoleByNo(HttpSession session){
		int upUId = Integer.parseInt(session.getAttribute("fuid").toString());
		Userrole urr = userroleBizimpl.findUserRoleByid(upUId);
		String url = "";
		if(urr != null){
			session.setAttribute("r", urr);
			url = "updateUsers";
		}else{
			url = "404";
		}
		return url;
	}

	
}


